<%@ page
	import="java.util.*,com.db.tracker.vo.*,java.util.*,com.db.tracker.util.*,java.text.*,java.io.*"%>
	<%@ page import="com.db.tracker.vo.UnixScriptBean"%>
<%
		try {
		session = request.getSession();
		//	System.out.println("user_id..main" +session.getAttribute("USER_ID"));

		//	temporary removed enable this line for login, and remove if(false){
		if (session.getAttribute("USER_ID") == null
		|| !((String) session.getAttribute("SESSION_ID"))
				.equals(session.getId())) {

			//	if(false){
			try {
		response.sendRedirect("LoginPage.jsp");
			} catch (IOException ioe) {
		ioe.printStackTrace();
			}

		} else {

			String usergroupname = (String) session
			.getAttribute("USER_GROUP_NAME");
			DBUtil dbutil = new DBUtil(getServletContext());
			ShellUtilities shellutil = new ShellUtilities(getServletContext());
			String userid = (String) session.getAttribute("USER_ID") == null ? ""
			: (String) session.getAttribute("USER_ID");

			// remove the existing release names stored in session, when user Add new release or change the release status.
			session.removeAttribute("allRelVector");
			session.removeAttribute("REL-NAME-VECTOR");
			session.removeAttribute("OPEN-REL-NAME-VECTOR");

			//	userid = "ronaksureshbhai.patel@cgi.com";
			//	System.out.println("userid1 :"+userid);
%>
<html>
<head>
<link type="text/css" rel="stylesheet" href="styles/tracker_style.css">
<title>Release Admin Page</title>
<script>

	function trim(sString)
		  {
			sTrimmedString = "";
		   if (sString != "") {
			  var iStart = 0;
			  var iEnd = sString.length - 1;
			 // var sWhitespace = " \t\f\n\r\v";
			 var sWhitespace = "   ";


			  while (sWhitespace.indexOf(sString.charAt(iStart)) != -1) {
				 iStart++;
				 if (iStart > iEnd) 
					break;
			  }

			  // If the string not just whitespace
			  if (iStart <= iEnd) {
				 while (sWhitespace.indexOf(sString.charAt(iEnd)) != -1)
					iEnd--;
				 sTrimmedString = sString.substring(iStart,++iEnd);
			  }
		   }
		   return sTrimmedString;
		 }

	function changeStatus(){
		document.ReleaseStatusForm.action="UnixReleaseAdmin.jsp";
		document.ReleaseStatusForm.submit();
	}

	function checkForEmpty(obj){
		  	
					// alert("obj.value.length"+obj.value);
			
				obj.value = trim(obj.value);
	
				if (obj.value.length == 0 )
				{
					alert("Please enter New Release Name.");
					obj.focus();
					return false;
				}

				document.AddReleaseForm.submit();
				
		} 	
	
	function openReleaseAdminDetails(ReleaseNameID) {
		dwin=window.open("EditReleaseAdmin.jsp?releaseNameID="+ReleaseNameID,"detailWin","width=700,height=160,scrollbars=yes,resizable=No");
		dwin.focus();
		
		}

	function openAddNewAdmin(){
		dwin=window.open("AdminUserManagement.jsp?","detailWin","width=700,height=160,scrollbars=yes,resizable=No");
		dwin.focus();
	
	}
	
	function manageSchedule(){
		document.ManageScheduleForm.submit();
	}

	function manageDataServer(){
		document.ManageServerForm.submit();
	}
	
	</script>
</head>

<body>
<table width="100%">
	<tr>
		<td width=100%><jsp:include page="HeaderNav_ReleaseObject.jsp" /></td>
	</tr>
</table>
<%
			java.text.SimpleDateFormat jsformatter = new java.text.SimpleDateFormat(
			"d MMM yyyy");
			String todate = jsformatter.format(new java.util.Date());
			int relNameID = Integer.parseInt(request
			.getParameter("HiddenReleaseNameID") == null ? "0"
			: request.getParameter("HiddenReleaseNameID"));
			String relStatus = request.getParameter("releaseStatus") == null ? ""
			: request.getParameter("releaseStatus");
			String AddRelButton = request.getParameter("AddRelButton") == null ? ""
			: request.getParameter("AddRelButton");
			String NewRelName = request.getParameter("NewRelName") == null ? ""
			: request.getParameter("NewRelName");
			String hiddenRelName = request
			.getParameter("HiddenRelName") == null ? ""
			: request.getParameter("HiddenRelName");
			String signedoffStatus = request
			.getParameter("signedoffStatus") == null ? ""
			: request.getParameter("signedoffStatus");

			//	System.out.println(">>> hiddenRelName :"+hiddenRelName);
			//	System.out.println(">>> relStatus :"+relStatus);
			if (relStatus.equals("OPEN") || relStatus.equals("CLOSE")
			|| signedoffStatus.equals("Y")
			|| signedoffStatus.equals("N")) {
		boolean statusflag = false;
		statusflag = shellutil.changeReleaseStatus(relNameID,
				relStatus, userid, signedoffStatus);
		if (statusflag == true) {
%>

<script type="text/javascript">
					var relName = '<%= hiddenRelName %>';
					var relStatus = '<%= relStatus %>';
					var signedoffStatus = '<%= signedoffStatus %>';
					alert(relName + " release status is : "+relStatus+" \n Signed off Flag is : "+signedoffStatus );
				</script>
<%
} else {
%>
<script language="JavaScript">
					alert("Error occured while changing Release Status/Signedoff flag, Kindly try again after sometime.");
				</script>
<%
			}
			}

			if (AddRelButton.equals("Add")) {
		boolean addRelFlag = true;
		addRelFlag = shellutil.addNewRelease(NewRelName, userid);

		if (addRelFlag == false) {
%>
<script>
					alert("The same Release Name is already there, Kindly enter different Name.");
				</script>
<%
			}

			}

			Vector relNameVector = shellutil.getReleaseStatus();
%>




<a href="mainpage.jsp">Back to Main.</a>

<table>
	<tr>
		<td align=right>&nbsp</td>
	</tr>
</table>

<table cellpadding="0" cellspacing="1" width="50%"
	style="BORDER:#000000 1px solid" align='center' colspan=2>
	<form name="AddReleaseForm" action="UnixReleaseAdmin.jsp" method="post">
	<tr bgcolor=#000077>
		<td class=smallfonthead align=left colspan=2><b>Add New
		Release Name</b></td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=center><input type=text
			name="NewRelName" size="50"></td>
		<td><input type=submit class=whitebutton name=AddRelButton
			value="Add" onclick="return checkForEmpty(NewRelName)" align=center></td>
	</tr>
	</form>
</table>



<table>
	<tr>
		<td>&nbsp</td>
	</tr>
</table>
<table cellpadding="0" cellspacing="1" width="50%"
	style="BORDER:#000000 1px solid" align='center' colspan=4>
	<tr bgcolor=#000077>
		<td class=smallfonthead align=left colspan=4><b>Release
		Status</b></td>
	</tr>
	<tr bgcolor=#000077>
		<td class=smallfonthead align=left width='10%' colspan=1><b>#</b></td>
		<td class=smallfonthead align=left width='60%' colspan=1><b>Release
		Name</b></td>
		<td class=smallfonthead align=left width='15%' colspan=1><b>Status</b></td>
	</tr>
	<%
			for (int i = 0; i < relNameVector.size(); i++) {
			ReleaseVO relbean = (ReleaseVO) relNameVector
					.elementAt(i);
	%>

	<form name="ReleaseStatusForm" action="UnixReleaseAdmin.jsp" method="post">
	<input type=hidden name=HiddenReleaseNameID
		value=<%=relbean.getReleaseNameID()%>> <input type=hidden
		name=HiddenRelName value=<%=relbean.getReleaseName()%>>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=center><%=i + 1%></td>
		<td class=bodyblue align=left>
		<!-- <a href="javascript:openReleaseAdminDetails('<%=relbean.getReleaseNameID()%>')"><%=relbean.getReleaseName()%></a> -->
		<%=relbean.getReleaseName()%>
			
	   </td>
		<td class=bodyblue align=center><select name=releaseStatus
			onchange='submit()'>
			<option value='OPEN'
				<%="OPEN".equals(relbean.getReleaseStatus())?"selected":""%>>
			<%="OPEN"%></option>

			<option value='CLOSE'
				<%="CLOSE".equals(relbean.getReleaseStatus())?"selected":""%>>
			<%="CLOSE"%></option>
		</select></td>


	</tr>
	</form>
	<%
	}
	%>
</table>

<table>
	<tr>
		<td align=right>&nbsp</td>
	</tr>
</table>
</body>
</html>





<%
	}
	} catch (Exception e) {
		e.printStackTrace();
	}
%>
